package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.api.bean.GoodsDetail
import client.comm.baoding.ui.viewmodel.MiddleVm

class GoodsDetailModel(app: Application) : MiddleVm(app) {


    val goodsDetail = MutableLiveData<JsonResult<GoodsDetail>>()

    val isShowingDialog = MutableLiveData<Boolean>(false)
    val isShowing = MutableLiveData<Boolean>(false)
    val buyRet = MutableLiveData<JsonResult<Ret>>()


    fun holdCall(id: String) {
        hold({
            server.goods_detail("${id}", "")
        }, {
            isShowing.value = true
        }, success = {
            goodsDetail.value = it
        }, complete = {
            isShowing.value = false

        })
    }

    fun add_shopping_cart(goodsId: String, num: String) {
        hold({
            server.add_shopping_cart(
                goodsId,
                num,
            )
        }, {
            isShowing.value = true
        }, success = {
            buyRet.value = it
        }, complete = {
            isShowing.value = false
        })
    }

}